package com.phone.entity;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cascade;
/**
 * 用户可以有多个购物项
 * 使用一对多实现购物车
 * @author 比尔·盖才
 *
 */

@Entity
@Table(name="user",uniqueConstraints={@UniqueConstraint(columnNames={"id"})})
public class User {
	private Integer id;
	private String username;
	private String password;
	private String name;
	private String autograph;
	private String email;
	private String telephone;
	private Set<CartItml> cartItmls=new HashSet<CartItml>();
	
	public User() {
		super();
	}
	public User(Integer id, String username, String password, String name, String autograph, String email,
			String telephone, Set<CartItml> cartItmls) {
		super();
		this.id = id;
		this.username = username;
		this.password = password;
		this.name = name;
		this.autograph = autograph;
		this.email = email;
		this.telephone = telephone;
		this.cartItmls = cartItmls;
	}
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Column(name="name")
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(name="password")
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	@Column(name="email")
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	@Column(name="username")
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	@Column(name="telephone")
	public String getTelephone() {
		return telephone;
	}
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	@Column(name="autograph")
	public String getAutograph() {
		return autograph;
	}
	public void setAutograph(String autograph) {
		this.autograph = autograph;
	}
	
	@OneToMany(targetEntity=CartItml.class,mappedBy="user",fetch=FetchType.EAGER,cascade=CascadeType.MERGE)
	public Set<CartItml> getCartItmls() {
		return cartItmls;
	}
	public void setCartItmls(Set<CartItml> cartItmls) {
		this.cartItmls = cartItmls;
	}
	@Override
	public String toString() {
		return "User [id=" + id + ", username=" + username + ", password=" + password + ", name=" + name
				+ ", autograph=" + autograph + ", email=" + email + ", telephone=" + telephone + "]";
	}	
}
